<!DOCTYPE html>
<html>
<head>
<title>添加内容</title>
#include("../include/common.html")
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>添加内容</h5>
            </div>
           <form id="inputForm" action="save" method="post">
                <input type="hidden" name="modelId" value="#(modelId)">
                <div class="ibox-content">
                    <div class="form-horizontal clearfix">
                    #for(modelField : modelFields)
                            #if(modelField.type=="input" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="#(modelField.name)" value="#(modelField.fieldAttribute.defaultValue)" class="form-control"/>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="textarea" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-8">
                                        <textarea name="#(modelField.name)" class="form-control" style="height: 250px;">#(modelField.fieldAttribute.defaultValue)</textarea>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="editor" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-8">
                                        <textarea name="#(modelField.name)" class="ibox-content no-padding fieldEditor" style="height: 250px;">#(modelField.fieldAttribute.defaultValue)</textarea>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="radio" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <div class="radio">
                                            #for(radioAttribute : modelField.fieldAttribute.radioAttributes)
                                                <label class="m-r"><input name="#(modelField.name)" value="#(radioAttribute[1])" type="radio" #if(modelField.fieldAttribute.defaultValue==radioAttribute[1]) checked #end>#(radioAttribute[0])</label>
                                            #end
                                        </div>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="checkbox" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <div class="checkbox">
                                            #for(checkboxAttribute : modelField.fieldAttribute.checkboxAttributes) 
                                                <label class="m-r"><input name="#(modelField.name)" value="#(checkboxAttribute[1])" type="checkbox" #if(modelField.fieldAttribute.defaultValue==checkboxAttribute[1]) checked #end>#(checkboxAttribute[0])</label>
                                            #end
                                        </div>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="select" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <select class="form-control" name="#(modelField.name)">
                                            #for(selectAttribute : modelField.fieldAttribute.selectAttributes)
                                                <option value="#(selectAttribute[1])" #if(modelField.fieldAttribute.defaultValue==selectAttribute[1]) checked #end>#(selectAttribute[0])</option>
                                            #end
                                        </select>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="date" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="#(modelField.name)" value="#(modelField.fieldAttribute.defaultValue)" class="form-control Wdate" onfocus="WdatePicker({dateFmt: '#(modelField.fieldAttribute.format)'});" />
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                </div>
                            #else if(modelField.type=="file" && modelField.isEnabled)
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-3">
                                        <input type="text" name="#(modelField.name)" value="#(modelField.fieldAttribute.defaultValue)" class="form-control"/>
                                        #if(modelField.prompt??)<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>#(modelField.prompt)</span>#end
                                    </div>
                                    <div class="col-sm-3">
                                        <a href="javascript:;" class="btn btn-primary fieldFilePicker">选择文件</a>
                                    </div>
                                </div>
                            #else if(modelField.type=="multipleFile" && modelField.isEnabled)
                                <div class="form-group" data-name="#(modelField.name)">
                                    <label class="col-sm-3 control-label">#(modelField.alias)：</label>
                                    <div class="col-sm-8">
                                        <a href="javascript:;" class="btn btn-primary fieldMultipleFilePicker">选择文件</a>
                                    </div>
                                    <div class="col-sm-3"></div>
                                    <div class="col-sm-8 multipleFile"></div>
                                </div>
                            #end
                        #end
                    </div>
                </div>
                <div class="modal-footer col-sm-3 col-sm-offset-2">
                    <button type="submit" class="btn btn-w-m btn-primary">确定</button>
                    <button type="button" class="btn btn-w-m btn-default" onclick="history.back(); return false;">取消</button>
                </div>
            </form>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
$().ready(function() {

    var $inputForm = $("#inputForm");
    var $introduction = $("#introduction");
    var $filePicker = $("#filePicker");
    
    $filePicker.uploader();
    $introduction.editor();
    
    $.each($(".fieldEditor"),function(index,item){
        $(item).editor();
    });
    
    $.each($(".fieldFilePicker"),function(index,item){
        $(item).uploader();
    });
    
    $.each($(".fieldMultipleFilePicker"),function(index,item){
        $(item).uploader({multiple:true});
    });
    
    $(".multipleFile").on("click","a",function(){
        $(this).parent().remove();
    });
    
    // 表单验证
    $inputForm.validate({
        rules: {
            #for(modelField : modelFields)
                #if(modelField.isEnabled && (modelField.isRequired || modelField.pattern??))
                	#if(rulesIndex>0),#end #(modelField.name): {
                        #if(modelField.isRequired && modelField.pattern??)
                            required: true,
                            pattern: #(modelField.pattern)
                        #else if(modelField.isRequired)
                            required: true
                        #else if(modelField.pattern)
                            pattern: #(modelField.pattern)
                        #end
                    }
                #end
             #end
        },
        messages: {
            #set(modelFieldIndex=0)
            #for(modelField : modelFields)
                #if(modelField.isEnabled && modelField.pattern??)
                    #if(modelFieldIndex>0),#end #(modelField.name): {
                        pattern: "#(modelField.alias)错误"
                    }
                    #set(modelFieldIndex=modelFieldIndex+1)
                #end   
            #end
        }
    });

});
</script>